<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        ul,
        li {
            list-style: none;
        }

        li {
            width: 200px;
            height: 100px;
            background: blueviolet;
            margin: 10px;
        }

        #box {
            width: 500px;
            height: 500px;
            border: 3px dotted pink;
            margin-left: 300px;
        }
    </style>
</head>

<body>
    <!--  draggable="true" 允许拖拽 -->
    <ul>
        <li draggable="true">1</li>
        <li draggable="true">2</li>
        <li draggable="true">3</li>
    </ul>

    <div id="box"></div>
    <script>
        //1.获取元素信息
        var oUl = document.getElementsByTagName('ul')[0];//getElementsByTagName 获取的是一个数组，必须获取到这个数组的0号元素才可以

        var aLi = oUl.getElementsByTagName('li');
        console.log(aLi);
        var oBox = document.getElementById('box');

        //2.给 li绑定拖拽事件
        for (var i = 0; i < aLi.length; i++) {
            // 2.1 dragstart  开始拖拽
            aLi[i].ondragstart = function () {
                console.log("开始拖拽触发了");
                //将小方块的背景更改为 蓝色
                this.style.background = "blue";
            }

            //2.2 drag 拖拽中
            var a = 1;
            aLi[i].ondrag = function () {
                // console.log("拖拽中" + a);
                a++;
            }
            //2.3 拖拽结束
            aLi[i].ondragend = function () {
                console.log("拖拽结束了");
                this.style.background = "yellow";
            }
        }

        //3 .目的地
        //3.1 进入目标元素
        oBox.ondragenter = function () {
            this.style.background = "orange";
        }
        //3.2 在目标上悬停
        var b = 0;
        oBox.ondragover = function () {
            console.log("悬停中" + b);
            b++;
        }
        //3.3 离开目标元素
        oBox.ondragleave = function () {
            this.style.background = "green";
        }

        //拖拽api的执行顺序：ondragstart  ondrag  ondragenter  ondragover  ondragleave  ondragend
    </script>
</body>

</html>